package com.battle.service.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.battle.pojo.entity.ExamStudyDetails;
import com.battle.pojo.param.examStudyDetails.*;
import com.battle.pojo.vo.examStudyDetails.*;
import com.battle.pojo.dto.examStudyDetails.*;
import com.battle.service.repository.in.ExamStudyDetailsRepository;
import com.battle.service.service.in.ExamStudyDetailsService;
import nirvana.core.domains.vo.PageResult;
import nirvana.core.utils.ids.IdGenerator;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;


import java.util.ArrayList;
import java.util.List;

/**
* 【描 述】：用户考试详情管理服务
* 【环 境】：J2SE 17
* 【详 细】：
*
*/
@Service
public class ExamStudyDetailsServiceImpl implements ExamStudyDetailsService {

private final ExamStudyDetailsRepository examStudyDetailsRepository;

public ExamStudyDetailsServiceImpl(ExamStudyDetailsRepository examStudyDetailsRepository) {
this.examStudyDetailsRepository = examStudyDetailsRepository;
}


/**
* 创建用户考试详情管理
*
* @param param
*/
@Override
public void createExamStudyDetails(CreateExamStudyDetailsParam param) {
ExamStudyDetails examStudyDetails =new ExamStudyDetails();
BeanUtils.copyProperties(param,examStudyDetails);
Long id = IdGenerator.SNOW.generate();
examStudyDetails.setId(id);
examStudyDetailsRepository.create(examStudyDetails);
}

/**
* 修改用户考试详情管理
*
* @param param
*/
@Override
public void editExamStudyDetails(EditExamStudyDetailsParam param) {
Long id = param.getId();
ExamStudyDetails examStudyDetails =examStudyDetailsRepository.getByIdCheck(id);
BeanUtils.copyProperties(param,examStudyDetails);
examStudyDetailsRepository.edit(examStudyDetails);
}

/**
* 移除用户考试详情管理
*
* @param id
*/
@Override
public void removeExamStudyDetails(Long id) {
examStudyDetailsRepository.removeById(id);
}

/**
* 启动/禁用用户考试详情管理
*
* @param id
*/
@Override
public void enabledExamStudyDetails(Long id) {
ExamStudyDetails examStudyDetails =examStudyDetailsRepository.getByIdCheck(id);
examStudyDetails.setIsDisable(!examStudyDetails.getIsDisable());
examStudyDetailsRepository.edit(examStudyDetails);
}

/**
* 获取用户考试详情管理详情
*
* @param id
* @return
*/
@Override
public GetExamStudyDetailsVo getExamStudyDetails(Long id) {
ExamStudyDetails examStudyDetails =examStudyDetailsRepository.getByIdCheck(id);
GetExamStudyDetailsVo vo=new GetExamStudyDetailsVo();
BeanUtils.copyProperties(examStudyDetails,vo);
return vo;
}

/**
* 获取用户考试详情管理 列表
*
* @param param
* @return
*/
@Override
public PageResult< GetExamStudyDetailsListVo> getExamStudyDetailsList(GetExamStudyDetailsListParam param) {

SelectExamStudyDetailsDto dto = new SelectExamStudyDetailsDto();
BeanUtils.copyProperties(param,dto);
Page< ExamStudyDetails > page = examStudyDetailsRepository.selectExamStudyDetails(dto);
List< ExamStudyDetails > examStudyDetailsList = page.getRecords();
List< GetExamStudyDetailsListVo > list= new ArrayList<>();
for (ExamStudyDetails examStudyDetails : examStudyDetailsList) {
GetExamStudyDetailsListVo vo=new GetExamStudyDetailsListVo();
BeanUtils.copyProperties(examStudyDetails,vo);

list.add(vo);
}
return new PageResult<>(list,page);

}

/**
* 获取用户考试详情管理下拉列表
*
* @param param
* @return
*/
@Override
public List< GetExamStudyDetailsDownListVo > getExamStudyDetailsDownList(GetExamStudyDetailsDownListParam param) {
ExamStudyDetails po = new ExamStudyDetails();
if (param != null) {
BeanUtils.copyProperties(param, po);
}
List< ExamStudyDetails > examStudyDetailsList = examStudyDetailsRepository.getListByEntity(po);

List< GetExamStudyDetailsDownListVo > list = new ArrayList<>();
for (ExamStudyDetails examStudyDetails : examStudyDetailsList) {
GetExamStudyDetailsDownListVo vo=new GetExamStudyDetailsDownListVo();
BeanUtils.copyProperties(examStudyDetails,vo);
list.add(vo);
}
return list;
}


}



